﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PBO.Forms.DataForm;
using PBO.Forms.NetworkForm;

namespace PBO
{
    public partial class IndexForm : Form
    {
        #region Instance

        private static IndexForm instance;

        public static IndexForm GetInstance()
        {
            if (instance == null || instance.IsDisposed)
                instance = new IndexForm();
            instance.MdiParent = MainForm.GetInstance();
            return instance;
        }

        public static IndexForm GetInstance(Form form)
        {
            if (instance == null || instance.IsDisposed)
                instance = new IndexForm();
            if (form != null)
                instance.MdiParent = form;
            return instance;
        }

        #endregion

        public IndexForm()
        {
            InitializeComponent();
            this.Icon = Properties.Resources.PokemonBall;
        }

        #region button

        private MainForm mdiForm;

        private void cmdTeam_Click(object sender, EventArgs e)
        {
            TeamEditorForm.GetInstance().Show();
            this.Hide();
        }

        private void cmdBattle_Click(object sender, EventArgs e)
        {
            var selector = new SelectorForm();
            selector.MdiParent = this.MdiParent;
            Hide();
            selector.Show();
            selector.FormClosed += BattleFormClosed;
        }

        private void BattleFormClosed(object sender, FormClosedEventArgs e)
        {
            ((Form)sender).FormClosed -= BattleFormClosed;
            Show();
        }

        private void cmdExit_Click(object sender, EventArgs e)
        {
            mdiForm.Close();
        }

        #endregion

        #region event

        private void IndexForm_Load(object sender, EventArgs e)
        {
            mdiForm = (MainForm)this.MdiParent;
        }

        #endregion

    }
}
